#include "junix.h"

int main(int argc, char **argv)
{
	int fd=connect_tcp("localhost","80");
	char buf[100]="Hello,World!\n";
	struct timeval tv={5,0};
	fd_set rd_set;
	FD_ZERO(&rd_set);
	FD_SET(fd,&rd_set);

	while(1)
	{
		Write(fd,buf,100);
		int ret=select(fd+1,&rd_set,NULL,NULL,&tv);
		if(ret==-1)
			err_sys("select");
		if(!ret)
			err_quit("time out");

		ssize_t sz;
		if( FD_ISSET(fd, &rd_set) )
			sz=Read(fd,buf,100);

		Write(STDOUT_FILENO,buf,sz);
	}
	exit(0);
}

